package com.xb.xbpm.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xb.xbpm.bean.Site;
import com.xb.xbpm.mapper.SiteMapper;
import com.xb.xbpm.service.ISiteService;
import com.xb.xbpm.utils.Tools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author gxd
 * @Date： 2018/7/25
 */
@Service
public class SiteService implements ISiteService {
    @Autowired
    SiteMapper siteMapper;

    @Override
    public Integer saveSite(Site site) throws Exception {
        Integer r=0;
        if(Tools.notEmpty(site.getId())){
            r=siteMapper.updateByPrimaryKeySelective(site);
        }else{
            site.setId(Tools.getOrderIdByUUId());
            r=siteMapper.insertSelective(site);
        }
        return r;
    }

    @Override
    public Integer delSiteInfo(String siteId) {
        Integer r=0;
        r =siteMapper.deleteByPrimaryKey(siteId);
        return r;
    }

    @Override
    public List<Map<String, Object>> getSiteList(String userid) {
        List<Map<String, Object>> list=siteMapper.getSiteListByUserId(userid);
        return list;
    }


    @Override
    public Site getSiteInfo(String id) {
        return siteMapper.getSiteInfoById(id);
    }

    @Override
    public Integer editSite(Site site) {

        Integer r=siteMapper.updateByPrimaryKeySelective(site);
        return r;
    }


    @Override
    public List<Map<String, Object>> getInfoList(String page, String startTime, String endTime) {
        return null;
    }

    @Override
    public Integer updateStatus(String status, String msg, String id) {
        return null;
    }

    @Override
    public Page<Site> getListByPage(String userid, String siteindex, int pageNum, int pageSize) {

        Map<String, String> map = new HashMap<String, String>();
        map.put("userid", userid);
        if(Tools.notEmpty(siteindex)){
            map.put("siteindex", siteindex);
        }

        PageHelper.startPage(pageNum, pageSize);
        return siteMapper.selectListByPage(map);

    }
}
